package com.mit.service.design.dao.impl;

import java.util.List;

import com.mit.common.design.dto.StyleDTO;
import com.mit.common.exception.NoRecordUpdateException;
import com.mit.service.core.dao.AbstractDAO;
import com.mit.service.design.dao.IStyleMasterDAO;

public class StyleMasterDAOImpl extends AbstractDAO implements IStyleMasterDAO {

	@Override
	public StyleDTO createStyle(StyleDTO style) {
		Integer id = (Integer)  getSqlMapClientTemplate().insert("insertStyleMaster", style);
		style.setId(id);
		return style;
	}

	@Override
	public StyleDTO updateStyle(StyleDTO style) throws NoRecordUpdateException {
		int rc = getSqlMapClientTemplate().update("updateStyle", style);
		if(rc < 1)
			throw new NoRecordUpdateException();
		return style;
	}

	@Override
	public List<StyleDTO> retrievePagedStyles(String searchCode,
			String searchState, Integer orgId, Integer pageNo, Integer pageSize) {
		StyleDTO to = new StyleDTO();
		to.setCode(searchCode);
		to.setState(searchState);
		to.setOrgId(orgId);
		to.setPageNo(pageNo);
		to.setPageSize(pageSize);
		return getSqlMapClientTemplate().queryForList("retrievepagedStyles",	to);
	}

	@Override
	public Integer retrieveStyleRecordCount(String searchCode,
			String searchState, Integer orgId) {
		StyleDTO to = new StyleDTO();
		to.setCode(searchCode);
		to.setState(searchState);
		to.setOrgId(orgId);
		return (Integer) getSqlMapClientTemplate().queryForObject("retrievepagedStylesCount", to);
	}

	@Override
	public StyleDTO retrieveStyle(Integer id) {
		
		return (StyleDTO) getSqlMapClientTemplate().queryForObject("selectStyleById", id);
	}

	@Override
	public List<StyleDTO> retrievePagedSampleTasks(String searchCode,
			String taskState, Integer orgId, Integer pageNo, Integer pageSize) {
		StyleDTO to = new StyleDTO();
		to.setCode(searchCode);
		to.setSampleState(taskState);
		to.setOrgId(orgId);
		to.setPageNo(pageNo);
		to.setPageSize(pageSize);
		return getSqlMapClientTemplate().queryForList("selectePagedSamples",	to);
	}

	@Override
	public Integer retrieveSampleTaskCount(String searchCode, String taskState,
			Integer orgId) {
		StyleDTO to = new StyleDTO();
		to.setCode(searchCode);
		to.setSampleState(taskState);
		to.setOrgId(orgId);
		return (Integer) getSqlMapClientTemplate().queryForObject("selectSamplesCount", to);
	}

	@Override
	public StyleDTO updateSampleTask(StyleDTO style)
			throws NoRecordUpdateException {
		int rc = getSqlMapClientTemplate().update("updateSampleTask", style);
		if(rc < 1)
			throw new NoRecordUpdateException();
		return style;
	}

	@Override
	public StyleDTO updateDressTask(StyleDTO style)
			throws NoRecordUpdateException {
		int rc = getSqlMapClientTemplate().update("updateDressTask", style);
		if(rc < 1)
			throw new NoRecordUpdateException();
		return style;
	}



}
